function FrameManager()
{
	this.signal = new Signal();
	var _this = this;
	
	
	function render()
	{
		_this.signal.dispatchEvent( FrameManager.ENTER_FRAME );
		window.requestAnimationFrame( render );
	}
	
	render();
}



// static
FrameManager.ENTER_FRAME = "enterFrame";
FrameManager._instance = null;

FrameManager.getInstance = function()
{
	if( FrameManager._instance == null )
	{
		FrameManager._instance = new FrameManager();
	}
	
	return FrameManager._instance;
};


// public

FrameManager.prototype.signal = null;

FrameManager.prototype.addFrameListener = function( p_callback, p_context )
{
	this.signal.addListener( FrameManager.ENTER_FRAME, p_callback, p_context );
};

FrameManager.prototype.removeFrameListener = function( p_callback, p_context )
{
	this.signal.removeListener( FrameManager.ENTER_FRAME, p_callback, p_context );
};

// useful
window.requestAnimationFrame = (function()
{
	
    return  window.requestAnimationFrame       ||  //Chromium 
            window.webkitRequestAnimationFrame ||  //Webkit
            window.mozRequestAnimationFrame    || //Mozilla Geko
            window.oRequestAnimationFrame      || //Opera Presto
            window.msRequestAnimationFrame     || //IE Trident?
            function(callback, element){ //Fallback function
                window.setTimeout(callback, 16);                
            }
     
})();
